package com.edu.service;

import com.edu.bean.News;
import com.edu.bean.NewsComment;
import com.edu.dao.NewsDao;
import com.edu.dao.NewsCommentDao;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

public class AdminNewsService {
    private NewsDao newsDao = new NewsDao();
    private NewsCommentDao newsCommentDao = new NewsCommentDao();

    /**
     * 获取总记录数
     */
    public int adminGetTotalCount(String title) {
        return newsDao.findTotalCount(title);
    }

    /**
     * 分页获取新闻列表
     */
    public List<News> adminListNewsByPage(String title, int currentPage, int pageSize) {
        int start = (currentPage - 1) * pageSize;
        return newsDao.findByPage(title, start, pageSize);
    }

    /**
     * 获取所有新闻
     */
    public List<News> adminListNews() {
        return newsDao.findAll();
    }

    /**
     * 获取单个新闻
     */
    public News adminGetNews(Integer newsId) {
        return newsDao.findById(newsId);
    }

    /**
     * 添加新闻
     */
    public boolean adminAddNews(News news) {
        return newsDao.add(news);
    }

    /**
     * 更新新闻
     */
    public boolean adminUpdateNews(News news) {
        return newsDao.update(news);
    }

    /**
     * 删除新闻
     */
    public boolean adminDeleteNews(Integer newsId) {
        return newsDao.delete(newsId);
    }

    /**
     * 获取新闻评论列表
     */
    public List<Map<String, Object>> getNewsComments(Integer newsId) {
        return newsCommentDao.findCommentsByNewsId(newsId);
    }

    /**
     * 删除新闻评论
     */
    public boolean deleteNewsComment(Integer commentId) {
        return newsCommentDao.delete(commentId);
    }

    public void getNewsComments(HttpServletRequest request, HttpServletResponse response) {
    }
}